package com.example.hotfixdemo;
import android.content.Context;
import android.support.annotation.Keep;
import android.util.Log;

import com.taobao.sophix.PatchStatus;
import com.taobao.sophix.SophixApplication;
import com.taobao.sophix.SophixEntry;
import com.taobao.sophix.SophixManager;
import com.taobao.sophix.listener.PatchLoadStatusListener;
/**
 * Sophix入口类，专门用于初始化Sophix，不应包含任何业务逻辑。
 * 此类必须继承自SophixApplication，onCreate方法不需要实现。
 * 此类不应与项目中的其他类有任何互相调用的逻辑，必须完全做到隔离。
 * AndroidManifest中设置application为此类，而SophixEntry中设为原先Application类。
 * 注意原先Application里不需要再重复初始化Sophix，并且需要避免混淆原先Application类。
 * 如有其它自定义改造，请咨询官方后妥善处理。
 */
public class SophixStubApplication extends SophixApplication {
    private final String TAG = "SophixStubApplication";
    // 此处SophixEntry应指定真正的Application，并且保证RealApplicationStub类名不被混淆。
    @Keep
    @SophixEntry(MyRealApplication.class)
    static class RealApplicationStub {}
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//         如果需要使用MultiDex，需要在此处调用。
//         MultiDex.install(this);
        initSophix();
    }
    private void initSophix() {
        String appVersion = "1.1.0";
        try {
            appVersion = this.getPackageManager()
                    .getPackageInfo(this.getPackageName(), 0)
                    .versionName;
        } catch (Exception e) {
        }
        final SophixManager instance = SophixManager.getInstance();
        instance.setContext(this)
                .setAppVersion(appVersion)
                .setSecretMetaData("333561572-1", "2401b965b0dd42e9bf5964ff47d0f873", "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCYzeVxppNpQomiI7cfcWj/GcsFDSJjHPVA4/ms9DTp5ij44xxUkF/v/mZ458rAhTjjBDf3Ya2+Frepj2cajADaz+LjMBjFMu/Y2wDOnvBfTYNmbh23EQh7iyS10ugUXAA+GWQfZMIzN3KQyDvVdDidklXyABYhcyNjg7/dqeMxQ3Bn6eKABdZ9NCpRidy+l2Qk8Vhi5zkR75SNFH3daWIevTv6kNADLtqdmTNUWdDRAIsGPqafJ4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KLvtRv8wUq2b440iF7NP6ZaknvgGEZuf+R7t9vgQO8un33nuQpxJytP0fPPAPoqs0wqsdaipAoGAVRFncaxQqgRI0QN7maT+IwtX3e5+wiyAGiPOwDCZtHbdjIxDsZT2Rl7S5LU+koi8R1N/EeWIagzQoV88hEsFDiwaetM/yBbp92c4GesTXih2KMbnZge2t3FAo4/LHEzhZgBYOfnuEqPB+G4rzi+FMfln7EqxAtrHZ+CBqea1UbM=")
                .setEnableDebug(true)
                .setEnableFullLog()
                .setPatchLoadStatusStub(new PatchLoadStatusListener() {
                    @Override
                    public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) {
                        if (code == PatchStatus.CODE_LOAD_SUCCESS) {
                            Log.i(TAG, "sophix load patch success!");
                        } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
                            // 如果需要在后台重启，建议此处用SharePreference保存状态。
                            Log.i(TAG, "sophix preload patch success. restart app to make effect.");
                        }
                    }
                }).initialize();
    }
}